home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Analysis / Integrate XY < prev    next >
Text File  |  1994-02-18  |  1KB  |  37 lines

  1. | IntegrateXYPro(xWave, yWave, yDestWaveName)
  2. |    Produces trapezoidal integration of XY pair, new wave yDestWaveName contains integration.
  3. |    The XY pair is assumed to be sorted.
  4. |    You can sort with: Sort xWave, xWave, yWave
  5. |    Works only with Igor Pro
  6. Function IntegrateXYPro(xWave, yWave, yDestWaveName)
  7.     Wave/D xWave, yWave                        | input X, Y waves
  8.     String yDestWaveName                        | name to use for output wave
  9.     
  10.     Duplicate/O/D yWave, $yDestWaveName
  11.     
  12.     Wave/D yDest = $yDestWaveName
  13.     yDest[0]=0
  14.     yDest[1,]= yDest[p-1] + 0.5*(yWave[p] + yWave[p-1]) * (xWave[p] - xWave[p-1])
  15. End
  16.  
  17. | IntegrateXY(xWave, yWave)
  18. |    Produces trapezoidal integration of XY pair, replacing contents of yWave
  19. |    The XY pair is assumed to be sorted.
  20. |    You can sort with: Sort xWave, xWave, yWave
  21. |    Works with Igor Pro or Igor 1.2
  22. Function IntegrateXY(xWave, yWave)
  23.     Wave/D xWave, yWave                        | input/output X, Y waves
  24.     
  25.     Variable/D yp,ypm1,sum=0
  26.     Variable pt=1,n=numpnts(yWave)
  27.     ypm1=yWave[0]
  28.     yWave[0]= 0
  29.     do
  30.         yp= yWave[pt]
  31.         sum +=  0.5*(yp + ypm1) * (xWave[pt] - xWave[pt-1])
  32.         yWave[pt]= sum
  33.         ypm1= yp
  34.         pt+=1
  35.     while( pt<n )
  36. End
  37.